﻿using System;


namespace Demo_App
{
    class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            new GameManager().Run();

            //FrameworkConfiguration config = new FrameworkConfiguration();
            //config.Title = "FrameworkTest";
            //config.Width = 800;
            //config.Height = 600;

            //BasicFramework<DX9DeviceContext> framework = new BasicFramework<DX9DeviceContext>(config);

            //DX9DeviceSettings setting = new DX9DeviceSettings();
            //setting.AdapterNumber = 0;
            ////setting.CreationFlags = CreateFlags.HardwareVertexProcessing;

            //framework.InitializeDevice(setting);
            //framework.CreateDevice();


            //// Create new Logger
            //Logger log = new Logger(LoggingLevel.Low, false);

            //Logger.Info("Initialize Direct 3D");
            //// Set Initial Start Time
            //int startTime = 0;
            //float frameTime = 0;
            //double fps = 0;

            //// Create Render Form
            //form = new RenderForm("Yeast-Game");

            //if (form == null)
            //{
            //    Logger.Error("RenderForm konnte nicht erstellt werden", LoggingLevel.High);
            //}
            //else
            //{
            //    Logger.Info("RenderForm erstellt");
            //}


            //CreateFlags createFlags = CreateFlags.SoftwareVertexProcessing;

            //// Get Presnet Parameters
            //presentParameters = new PresentParameters();
            //// Create Direct3D
            //directX = new Direct3D();

            //Capabilities deviceCaps = directX.GetDeviceCaps(0, DeviceType.Hardware);
            //if (deviceCaps != null)
            //{
            //    if ((deviceCaps.DeviceCaps & DeviceCaps.HWTransformAndLight) == DeviceCaps.HWTransformAndLight)
            //    {
            //        createFlags = CreateFlags.HardwareVertexProcessing | CreateFlags.FpuPreserve;
            //    }
            //}

            //int multiSampleQualityLevel = 0;
            //int qualityLevelCkeck = 0;
            //MultisampleType multiSampleType = MultisampleType.None;
            //bool bSupported = false;

            //for (int i = (int)MultisampleType.NonMaskable; i < (int)MultisampleType.SixteenSamples; i++)
            //{
            //    bSupported = directX.CheckDeviceMultisampleType(0, DeviceType.Hardware, Format.A8R8G8B8, true, (MultisampleType)i, out qualityLevelCkeck);
            //    if (bSupported)
            //    {
            //        multiSampleType = (MultisampleType)i;
            //        multiSampleQualityLevel = qualityLevelCkeck - 1;
            //    }
            //    else
            //    {
            //        //break;
            //    }
            //}

            //presentParameters.BackBufferFormat = Format.A8R8G8B8;
            //presentParameters.BackBufferCount = 1;
            //presentParameters.BackBufferWidth = form.Width;
            //presentParameters.BackBufferHeight = form.Height;
            //presentParameters.Multisample = multiSampleType;
            //presentParameters.MultisampleQuality = multiSampleQualityLevel;
            //presentParameters.SwapEffect = SwapEffect.Discard;
            //presentParameters.EnableAutoDepthStencil = true;
            //presentParameters.AutoDepthStencilFormat = Format.D16;
            //presentParameters.PresentFlags = PresentFlags.DiscardDepthStencil;
            //presentParameters.PresentationInterval = PresentInterval.Default;
            //presentParameters.Windowed = true;
            //presentParameters.DeviceWindowHandle = form.Handle;

            //device = new Device(directX, 0, DeviceType.Hardware, form.Handle, createFlags, presentParameters);
            //device.SetRenderState(RenderState.AlphaBlendEnable, true);


            ////SetupCamera();


            //// Handle ALT + ENTER Shortcut for Fullscreen Switch
            //// Disable Key + Enter handling of DXGI


            //form.KeyDown += new KeyEventHandler(form_KeyDown);

            //// Handle Form Size changes
            //form.Resize += new EventHandler(form_Resize);

            //// Create Keyboard Manager
            //KeyboardManager keyboardManager = new KeyboardManager(form);

            //// Create Game Manager
            //GameManager gameManager = new GameManager(form, device);
            //gameManager.Init();

            //SetupCamera();

            ////
            //// Do Message Loop
            ////
            //MessagePump.Run(form, () =>
            //{
            //    // Clear Render Target
            //    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.LightBlue, 1.0f, 0);

            //    // Calculate FrameTime in sec
            //    frameTime = (0.001f * (Environment.TickCount - startTime)) / 10;
            //    // Calculate FPS
            //    fps = (1000.0f / (Environment.TickCount - startTime));
            //    // Set start Time
            //    startTime = Environment.TickCount;

            //    // Begin Scene
            //    device.BeginScene();

            //    // Move Game
            //    gameManager.Move(frameTime);

            //    // Render Frame
            //    gameManager.Render(frameTime);

            //    // Present everything
            //    device.EndScene();

            //    device.Present();
            //});


        }

        //static void SetupCamera()
        //{
        //    //device.SetRenderState(RenderState.CullMode, Cull.None);
        //    //device.SetRenderState(RenderState.Lighting, false);

        //    //// world
        //    //Matrix word = Matrix.Identity;
        //    //device.SetTransform(TransformState.World, word);

        //    //// view
        //    //Vector3 eye = new Vector3(0.0f, 0.0f, -5.0f);
        //    //Vector3 at = new Vector3(0.0f, 0.0f, 0.0f);
        //    //Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);
        //    //Matrix view = Matrix.LookAtLH(eye, at, up);
        //    //device.SetTransform(TransformState.View, view);

        //    //// projection
        //    //Matrix proj = Matrix.OrthoOffCenterLH(0f, form.Width, form.Height, 0f, 0.5f, 100.0f);
        //    //device.SetTransform(TransformState.Projection, proj);
        //}

        //static void form_Resize(object sender, EventArgs e)
        //{
        //    //renderTarget.Dispose();

        //    //swapChain.ResizeBuffers(2, 0, 0, Format.R8G8B8A8_UNorm, SwapChainFlags.AllowModeSwitch);
        //    //using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
        //    //    renderTarget = new RenderTargetView(device, resource);

        //    //context.OutputMerger.SetTargets(renderTarget);
        //}

        //static void form_KeyDown(object sender, KeyEventArgs e)
        //{
        //    //if (e.Alt && e.KeyCode == Keys.Enter)
        //    //{
        //    //    bool fullscreen;
        //    //    Output output;
        //    //    swapChain.GetFullScreenState(out fullscreen, out output);
        //    //    swapChain.SetFullScreenState(!fullscreen, output);
        //    //}
        //}


    }

}
